using JGSY.CMS.LowCode.Platform.Domain.Entities;

namespace JGSY.CMS.LowCode.Platform.Application.DTOs
{
    /// <summary>
    /// 租户资源使用概览
    /// </summary>
    public class TenantResourceUsageOverview
    {
        public string TenantId { get; set; } = string.Empty;
        public int TotalResourceTypes { get; set; }
        public int ActiveQuotas { get; set; }
        public int ResourcesNearingSoftLimit { get; set; }
        public int ResourcesExceedingSoftLimit { get; set; }
        public List<ResourceUsageInfo> ResourceUsages { get; set; } = new();
        public DateTime GeneratedAt { get; set; }
    }

    /// <summary>
    /// 资源使用信息
    /// </summary>
    public class ResourceUsageInfo
    {
        public string ResourceType { get; set; } = string.Empty;
        public long LimitValue { get; set; }
        public long CurrentUsage { get; set; }
        public long SoftLimit { get; set; }
        public decimal UsagePercentage { get; set; }
        public bool IsOverSoftLimit { get; set; }
        public bool IsOverHardLimit { get; set; }
    }

    /// <summary>
    /// 性能指标统计
    /// </summary>
    public class PerformanceMetricStatistics
    {
        public string MetricName { get; set; } = string.Empty;
        public double Average { get; set; }
        public double Minimum { get; set; }
        public double Maximum { get; set; }
        public double Sum { get; set; }
        public long Count { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
    }

    /// <summary>
    /// 租户健康度评分
    /// </summary>
    public class TenantHealthScore
    {
        public string TenantId { get; set; } = string.Empty;
        public double OverallScore { get; set; }
        public Dictionary<string, double> ComponentScores { get; set; } = new();
        public List<string> Issues { get; set; } = new();
        public List<string> Recommendations { get; set; } = new();
        public DateTime CalculatedAt { get; set; }
    }

    /// <summary>
    /// 异常检测结果
    /// </summary>
    public class AnomalyDetectionResult
    {
        public string TenantId { get; set; } = string.Empty;
        public string MetricName { get; set; } = string.Empty;
        public double Value { get; set; }
        public double Threshold { get; set; }
        public string AnomalyType { get; set; } = string.Empty;
        public double Severity { get; set; }
        public DateTime DetectedAt { get; set; }
        public Dictionary<string, object> Context { get; set; } = new();
    }

    /// <summary>
    /// 租户比较结果
    /// </summary>
    public class TenantComparisonResult
    {
        public string TenantId { get; set; } = string.Empty;
        public string MetricName { get; set; } = string.Empty;
        public double Value { get; set; }
        public double Average { get; set; }
        public double Percentile { get; set; }
        public string ComparisonType { get; set; } = string.Empty;
    }

    /// <summary>
    /// 租户监控报告
    /// </summary>
    public class TenantMonitoringReport
    {
        public string TenantId { get; set; } = string.Empty;
        public string ReportType { get; set; } = string.Empty;
        public DateTime PeriodStart { get; set; }
        public DateTime PeriodEnd { get; set; }
        public Dictionary<string, object> Summary { get; set; } = new();
        public List<PerformanceMetricStatistics> PerformanceMetrics { get; set; } = new();
        public List<TenantActivityStatistic> ActivityStatistics { get; set; } = new();
        public List<AnomalyDetectionResult> Anomalies { get; set; } = new();
        public TenantHealthScore HealthScore { get; set; } = new();
        public DateTime GeneratedAt { get; set; }
    }

    /// <summary>
    /// 性能趋势DTO
    /// </summary>
    public class TenantPerformanceTrendDto
    {
        public DateTime Period { get; set; }
        public double Value { get; set; }
        public string IntervalType { get; set; } = string.Empty;
    }

    /// <summary>
    /// 成本趋势DTO
    /// </summary>
    public class TenantCostTrendDto
    {
        public DateTime Period { get; set; }
        public decimal Amount { get; set; }
        public string CostType { get; set; } = string.Empty;
        public string IntervalType { get; set; } = string.Empty;
    }

    /// <summary>
    /// 租户告警DTO
    /// </summary>
    public class TenantAlertDto
    {
        public string TenantId { get; set; } = string.Empty;
        public string AlertType { get; set; } = string.Empty;
        public string Message { get; set; } = string.Empty;
        public string Severity { get; set; } = string.Empty;
        public DateTime TriggeredAt { get; set; }
        public Dictionary<string, object> Context { get; set; } = new();
    }

    /// <summary>
    /// 租户仪表板DTO
    /// </summary>
    public class TenantDashboardDto
    {
        public string TenantId { get; set; } = string.Empty;
        public Dictionary<string, double> PerformanceMetrics { get; set; } = new();
        public Dictionary<string, long> ActivitySummary { get; set; } = new();
        public Dictionary<string, decimal> CostSummary { get; set; } = new();
        public List<TenantAlertDto> Alerts { get; set; } = new();
        public TenantHealthScore HealthScore { get; set; } = new();
        public DateTime GeneratedAt { get; set; }
    }

    /// <summary>
    /// 迁移进度
    /// </summary>
    public class MigrationProgress
    {
        public long MigrationId { get; set; }
        public string CurrentStep { get; set; } = string.Empty;
        public int TotalSteps { get; set; }
        public int CompletedSteps { get; set; }
        public double PercentComplete { get; set; }
        public long ProcessedRecords { get; set; }
        public long TotalRecords { get; set; }
        public DateTime LastUpdated { get; set; }
    }

    /// <summary>
    /// 租户数据统计
    /// </summary>
    public class TenantDataStatistics
    {
        public string TenantId { get; set; } = string.Empty;
        public long TotalRecords { get; set; }
        public long TotalSize { get; set; }
        public Dictionary<string, long> TableCounts { get; set; } = new();
        public Dictionary<string, long> TableSizes { get; set; } = new();
        public DateTime CalculatedAt { get; set; }
    }

    /// <summary>
    /// 数据增长趋势
    /// </summary>
    public class DataGrowthTrend
    {
        public DateTime Period { get; set; }
        public long RecordCount { get; set; }
        public long DataSize { get; set; }
        public string GrowthRate { get; set; } = string.Empty;
    }

    /// <summary>
    /// 存储使用分析
    /// </summary>
    public class StorageUsageAnalysis
    {
        public string TenantId { get; set; } = string.Empty;
        public long TotalSize { get; set; }
        public long UsedSize { get; set; }
        public long FreeSize { get; set; }
        public double UsagePercentage { get; set; }
        public Dictionary<string, long> CategoryBreakdown { get; set; } = new();
        public List<DataGrowthTrend> GrowthTrend { get; set; } = new();
        public DateTime AnalyzedAt { get; set; }
    }

    /// <summary>
    /// 数据质量问题
    /// </summary>
    public class DataQualityIssue
    {
        public string TenantId { get; set; } = string.Empty;
        public string TableName { get; set; } = string.Empty;
        public string IssueType { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public string Severity { get; set; } = string.Empty;
        public long AffectedRecords { get; set; }
        public Dictionary<string, object> Details { get; set; } = new();
        public DateTime DetectedAt { get; set; }
    }

    /// <summary>
    /// 数据管理报告
    /// </summary>
    public class DataManagementReport
    {
        public string TenantId { get; set; } = string.Empty;
        public string ReportType { get; set; } = string.Empty;
        public DateTime PeriodStart { get; set; }
        public DateTime PeriodEnd { get; set; }
        public TenantDataStatistics Statistics { get; set; } = new();
        public List<DataGrowthTrend> GrowthTrends { get; set; } = new();
        public StorageUsageAnalysis StorageAnalysis { get; set; } = new();
        public List<DataQualityIssue> QualityIssues { get; set; } = new();
        public Dictionary<string, object> Summary { get; set; } = new();
        public DateTime GeneratedAt { get; set; }
    }
}
